/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.apt.hobbiestag.process;

import com.apt.tag.Connect_DB;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Bach
 */
public class EnableHobbies {

    public static boolean setEnableHobbies(String hobbies_Name, String liking_Model_Id, String liking_Id) {

        String up = "UPDATE [Matrimony].[dbo].[Liking_Cates]\n"
                + "   SET [Liking_Status] = 1"
                + " where [Liking_Id]=? ";
        boolean re = false;
        Connection con = null;
        PreparedStatement ps = null;
        try {
            con = Connect_DB.getConnection();
            con.setAutoCommit(false);// transaction
            ps = con.prepareStatement(up);
            ps.setInt(1, Integer.parseInt(liking_Id));
            int i = ps.executeUpdate();
            if (i > 0) {
                if (setEnableLiking(liking_Id, con)) {
                    re = true;
                }
            }
            con.commit();
        } catch (SQLException e) {
            e.printStackTrace();
            try {
                con.rollback();
            } catch (SQLException ex) {
                Logger.getLogger(EnableHobbies.class.getName()).log(Level.SEVERE, null, ex);
            }
        } finally {
            Connect_DB.close(null, null, ps, con);
        }
        return re;
    }

    public static boolean setEnableLiking(String liking_Id, Connection con) {

        String up = "UPDATE [Matrimony].[dbo].[Liking_Models]\n"
                + "   SET [Liking_Model_Status] = 1\n"
                + " where [Liking_Id]=?";
        boolean re = false;
        PreparedStatement ps = null;
        try {

            ps = con.prepareStatement(up);
            ps.setInt(1, Integer.parseInt(liking_Id));
            int i = ps.executeUpdate();
            if (i > 0) {
                re = true;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return re;
    }
//    
//     String up = "UPDATE [Matrimony].[dbo].[Liking_Models]\n"
//                + "   SET [Liking_Model_Status] = 1\n"
//                + " where [Liking_Model_Name]=? and [Liking_Model_Id]=?";
//    
//    String up = "UPDATE [Matrimony].[dbo].[Liking_Cates]\n"
//                + "   SET [Liking_Status] = 1"
//                + " where [Liking_Id]=? ";
}
